home *** CD-ROM | disk | FTP | other *** search
/ Stolen Data 2 / Stolen Data 2.adf / Source / Cube.s next >
Text File  |  1989-11-02  |  5KB  |  339 lines

  1.     Incdir    Df1:
  2.     Include Source/CustomRegisters
  3.     Section    Cube,Code_c
  4.  
  5. Ciaapra = $BFE001
  6. Openlibrary = -30-522    
  7. Disable        = -120
  8. Enable        = -126
  9. Startlist   = 38
  10. Execbase = 4
  11.  
  12.     Move.l    Execbase,a6
  13.     Jsr    Disable(a6)
  14.  
  15. ;-------- Switch Copper DMA ----------
  16.  
  17.     Move.l    #Clstart,Cop1lc
  18.     Clr    Copjmp1
  19.  
  20.     Move.w    #$8780,Dmacon
  21.     Move.w    #$0020,Dmacon
  22.     Lea    Spr0data,a0
  23.     Moveq    #7,d0
  24. Clop
  25.     Clr.l    (a0)
  26.     Addq.l    #8,a0
  27.     Dbf    d0,Clop
  28.  
  29. ;------ Wait for Vertical position 1 --------
  30.  
  31. Wait:    Move.l    $dff004,d2
  32.     And.l    #$0001ff00,d2    
  33.     Cmp.l    #$00000100,d2
  34.     Bne.s    Wait
  35.  
  36.     Addq    #2,Zrot
  37.     And    #$1fe,Zrot
  38.     Addq    #4,Yrot
  39.     And    #$1fe,Yrot
  40.     Subq    #2,Xrot
  41.     And    #$1fe,Xrot
  42.     Bsr    TD_rout
  43.  
  44.     Btst    #6,Ciaapra
  45.     Bne    Wait
  46.  
  47. ;------ Restore old Copper list -----------
  48.  
  49.     Move.l    Execbase,a6
  50.     Move.l    #Grname,a1
  51.     Clr.l    d0
  52.     Jsr    Openlibrary(a6)
  53.     Move.l    d0,a4
  54.     Move.l    Startlist(a4),Cop1lc
  55.     Clr.w    Copjmp1
  56.     Move.w    #$83E0,Dmacon
  57.     Jsr    Enable(a6)
  58.     Clr.l    d0
  59.     Rts
  60.  
  61. ;--------- 3D graphics ------------
  62. TD_rout
  63.     Move.l    Current(pc),d0
  64.     Move    d0,Screen+2
  65.     Swap    d0
  66.     Move    d0,Screen+6
  67.     Eor.l    #$3000,Current
  68.     Move.l    Current(pc),a0
  69.     Move.l    #$1f00000,Bltcon0
  70.     Move.l    a0,Bltdpth
  71.     Clr    Bltadat
  72.     Clr    Bltdmod
  73.     Move    #256*64+20,Bltsize
  74.  
  75.     Move    #No_points-1,d7
  76.     Lea    Points(pc),a4    
  77.     Lea    Sintable+$40(pc),a1
  78.     Lea    Rotated_coords(pc),a2
  79.     Lea    Perspective(pc),a3
  80. TD_loop
  81.     Move    (a4)+,d0
  82.     Move    d0,d2
  83.     Move    (a4)+,d1
  84.     Move    d1,d3
  85.  
  86.     Move    Zrot(pc),d6
  87.     Move    $40(a1,d6),d4
  88.     Move    -$40(a1,d6),d5
  89.     Muls    d4,d0
  90.     Muls    d5,d1
  91.     Sub.l    d1,d0
  92.     Add.l    d0,d0
  93.     Swap    d0        ;d0 holds intermediate x coord
  94.     Muls    d5,d2
  95.     Muls    d4,d3
  96.     Add.l    d3,d2
  97.     Add.l    d2,d2
  98.     Swap    d2        ;d2 holds intermediate y coord
  99.     Move    d2,d4
  100.  
  101.     Move    (a4)+,d1    ;z coord
  102.     Move    d1,d3
  103.     Move    Xrot(pc),d6
  104.     Move    $40(a1,d6),d5
  105.     Move    -$40(a1,d6),d6
  106.     Muls    d5,d2
  107.     Muls    d6,d1
  108.     Sub.l    d1,d2
  109.     Add.l    d2,d2
  110.     Swap    d2        ;d2 holds the final y coord
  111.     Muls    d5,d3
  112.     Muls    d6,d4
  113.     Add.l    d4,d3
  114.     Add.l    d3,d3
  115.     Swap    d3        ;d3 holds intermediate z coord
  116.  
  117.     Move    d0,d1
  118.     Move    d3,d4
  119.     Move    Yrot(pc),d6
  120.     Move    $40(a1,d6),d5
  121.     Move    -$40(a1,d6),d6
  122.     Muls    d5,d3
  123.     Muls    d6,d0
  124.     Sub.l    d0,d3
  125.     Add.l    d3,d3
  126.     Swap    d3        ;d3 holds the final z coord
  127.     Muls    d6,d4
  128.     Muls    d5,d1
  129.     Add.l    d4,d1
  130.     Add.l    d1,d1
  131.     Swap    d1        ;d1 holds the final x coord
  132.  
  133.     Add    Depth(pc),d3
  134.     Add    d3,d3
  135.     Move    (a3,d3),d5
  136.     Muls    d5,d1
  137.     Muls    d5,d2
  138.     Add.l    d1,d1
  139.     Swap    d1
  140.     Add    #160,d1
  141.     Add.l    d2,d2
  142.     Swap    d2
  143.     Add    #128,d2
  144.     
  145.     Move    d1,(a2)+
  146.     Move    d2,(a2)+
  147.     Dbf    d7,TD_loop
  148.  
  149.     Move    #No_connects-1,d7
  150.     Lea    $dff000,a5
  151.     Lea    Connect(pc),a3
  152.     Lea    Rotated_coords(pc),a4
  153.     Moveq    #40,d0
  154.     Lea    Mul40(pc),a1
  155.     Lea    Bits(pc),a2
  156.     Lea    Faces(pc),a6
  157. B_wait2
  158.     Btst    #14,Dmaconr
  159.     Bne.s    B_wait2
  160.  
  161.     Move    #$ffff,Bltafwm
  162.     Move    d0,$60(a5)    ;Bltcmod
  163.     Move    d0,$66(a5)    ;Bltdmod
  164.     Move    #$ffff,$72(a5)    ;Bltbdat
  165. Draw_loop
  166.     Move    (a3)+,d6
  167.     Move    (a4,d6),d0
  168.     Move    2(a4,d6),d1
  169.     Move    (a3)+,d6
  170.     Move    (a4,d6),d2
  171.     Move    2(a4,d6),d3
  172.     Cmp    d0,d2
  173.     Bne.s    Draw
  174.     Cmp    d1,d3
  175.     Beq.s    Nodraw    
  176. Draw
  177.     Bsr    Line
  178. Nodraw
  179.     Dbf    d7,Draw_loop
  180. Bwit
  181.     Btst    #14,Dmaconr
  182.     Bne.s    Bwit
  183.     Rts
  184.  
  185. ;----------- Line Draw ------------
  186. Line
  187.     Moveq    #0,d4
  188.     Move    d1,d4
  189.     Add    d4,d4
  190.     Move    (a1,d4),d4
  191.     Moveq    #-$10,d5
  192.     And    d0,d5
  193.     Lsr    #3,d5
  194.     Add    d5,d4
  195.     Add.l    a0,d4
  196.  
  197.     Moveq    #0,d5
  198.     Sub    d1,d3
  199.     Roxl.b    d5
  200.     Tst    d3
  201.     Bge.s    Y2gy1
  202.     Neg    d3
  203. Y2gy1
  204.     Sub    d0,d2
  205.     Roxl.b    d5
  206.     Tst    d2
  207.     Bge.s    X2gx1
  208.     Neg    d2
  209. X2gx1
  210.  
  211.     Move    d3,d1
  212.     Sub    d2,d1
  213.     Bge.s    Dygdx
  214.     Exg    d2,d3
  215. Dygdx
  216.     Roxl.b    d5
  217.     Move.b    Octant_table(pc,d5),d5
  218.     Add    d2,d2
  219. Wblit
  220.     Btst    #14,Dmaconr
  221.     Bne.s    Wblit
  222.  
  223.     Move    d2,$62(a5)    ;Bltbmod
  224.     Sub    d3,d2
  225.     Bge.s    Signn1
  226.     Or.b    #$40,d5
  227. Signn1
  228.     Move    d2,$52(a5)    ;Bltaptl
  229.     Sub    d3,d2
  230.     Move    d2,$64(a5)    ;Bltamod
  231.  
  232.     Move    #$8000,$74(a5)    ;Bltadat
  233.     Add    d0,d0
  234.     Move    (a2,d0),$40(a5)    ;Bltcon0
  235.     Move    d5,$42(a5)    ;Bltcon1
  236.     Move.l    d4,$48(a5)    ;Bltcpth
  237.     Move.l    d4,$54(a5)    ;Bltdpth
  238.     Lsl    #6,d3
  239.     Addq    #2,d3
  240.     Move    d3,$58(a5)    ;Bltsize
  241.     Rts
  242.  
  243. ;---------- Constants -------------
  244.  
  245. Octant_table
  246.     Dc.b    1,17,9,21,5,25,13,29
  247.  
  248. Grname:    Dc.b    "graphics.library",0
  249.  
  250.     Even
  251.  
  252. ;----------- Variables ------------
  253.  
  254. Xrot    Dc.w    $100
  255. Yrot    Dc.w    0
  256. Zrot    Dc.w    0
  257. Current    Dc.l    $70000
  258. Depth    Dc.w    180
  259. Depthpt    Dc.w    0
  260.  
  261. ;---------- Copperlists -----------
  262. Clstart:
  263.     Wait    0,20
  264.     Mov    $1a81,Diwstrt
  265.     Mov    $39c1,Diwstop
  266.     Mov    $0038,Ddfstrt
  267.     Mov    $00d0,Diwstop
  268. Screen
  269.     Mov    0,Bpl1ptl
  270.     Mov    7,Bpl1pth
  271.     Mov    $1200,Bplcon0
  272.     Mov    0,Bpl1mod
  273.     Mov    0,Color00
  274.     Mov    $fff,Color01
  275.     Wait    224,255
  276.     Wait    $fe,$ff
  277.  
  278. ;--------- Binaries -------------
  279. No_points    = 8
  280. No_connects    = 12
  281. No_faces    = 6
  282.  
  283. Points
  284.     Dc.w    100,100,100
  285.     Dc.w    -100,100,100
  286.     Dc.w    -100,-100,100
  287.     Dc.w    100,-100,100
  288.  
  289.     Dc.w    100,100,-100
  290.     Dc.w    -100,100,-100
  291.     Dc.w    -100,-100,-100
  292.     Dc.w    100,-100,-100
  293.  
  294. Connect
  295.     Dc.w    0,4
  296.     Dc.w    4,8
  297.     Dc.w    8,12
  298.     Dc.w    12,0
  299.  
  300.     Dc.w    16,20
  301.     Dc.w    20,24
  302.     Dc.w    24,28
  303.     Dc.w    28,16
  304.  
  305.     Dc.w    0,16
  306.     Dc.w    4,20
  307.     Dc.w    8,24
  308.     Dc.w    12,28
  309.  
  310. Rotated_coords    
  311.     Dcb.w    No_points*2,0
  312. Sintable
  313.     Incbin    Binary/Sin
  314.     Incbin    Binary/Sin
  315. Perspective
  316.     Incbin    Binary/Perspective
  317.  
  318. Mul40
  319. A set 0
  320.     Rept    320
  321.     Dc.w    A*40
  322. A set A+1
  323.     Endr
  324.  
  325. A set 0
  326. Bits
  327.     Rept    320
  328.     Dc.w    ((A&$f)*$1000)+$bca
  329. A set A+1
  330.     Endr
  331.  
  332. Size
  333. A set 0
  334.     Rept    320
  335.     Dc.w    (A*64)+2
  336. A set A+1
  337.     Endr
  338.  
  339.